/*
package com.diana.common;

import com.diana.entity.ScheduleJob;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

*/
/**
 * 定时任务工具类
 *
 * @author Mark sunlightcs@gmail.com
 *//*

public class ScheduleUtils {

    private static Logger log = LoggerFactory.getLogger(ScheduleUtils.class);
    private final static String JOB_NAME = "TASK_";

    */
/**
     * 获取触发器key
     *//*

    public static TriggerKey getTriggerKey(Long jobId) {
        return TriggerKey.triggerKey(JOB_NAME + jobId);
    }

    */
/**
     * 获取jobKey
     *//*

    public static JobKey getJobKey(Long jobId) {
        return JobKey.jobKey(JOB_NAME + jobId);
    }

    */
/**
     * 获取表达式触发器
     *//*

    public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId) {
        try {
            return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
        } catch (SchedulerException e) {
            log.info("获取定时任务CronTrigger出现异常{}",e);
            return null;
        }
    }

    */
/**
     * 创建定时任务
     *//*

    public static boolean createScheduleJob(Scheduler scheduler, ScheduleJob scheduleJob) {
        try {
        	//构建job信息
            JobDetail jobDetail = JobBuilder.newJob(ExecuteJob.class).withIdentity(getJobKey(scheduleJob.getJobId())).build();

            //表达式调度构建器
            CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
            		.withMisfireHandlingInstructionDoNothing();

            //按新的cronExpression表达式构建一个新的trigger
            CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId())).withSchedule(scheduleBuilder).build();

            //放入参数，运行时的方法可以获取
            jobDetail.getJobDataMap().put(ScheduleJob.JOB_PARAM_KEY, scheduleJob);

            scheduler.scheduleJob(jobDetail, trigger);

            //暂停任务
            if(scheduleJob.getStatus() == 1){
            	pauseJob(scheduler, scheduleJob.getJobId());
            }
            return true;
        } catch (SchedulerException e) {
            log.info("创建定时任务失败{}",e);
            return false;
        }
    }

    */
/**
     * 更新定时任务
     *//*

    public static boolean updateScheduleJob(Scheduler scheduler, ScheduleJob scheduleJob) {
        try {
            TriggerKey triggerKey = getTriggerKey(scheduleJob.getJobId());

            //表达式调度构建器
            CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
            		.withMisfireHandlingInstructionDoNothing();

            CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getJobId());

            //按新的cronExpression表达式重新构建trigger
            trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();

            //参数
            trigger.getJobDataMap().put(ScheduleJob.JOB_PARAM_KEY, scheduleJob);

            scheduler.rescheduleJob(triggerKey, trigger);

            //暂停任务
            if(scheduleJob.getStatus() == 1){
            	pauseJob(scheduler, scheduleJob.getJobId());
            }
            return true;
        } catch (SchedulerException e) {
            log.info("更新定时任务失败{}",e);
            return false;
        }
    }

    */
/**
     * 立即执行任务
     *//*

    public static boolean run(Scheduler scheduler, ScheduleJob scheduleJob) {
        try {
        	//参数
        	JobDataMap dataMap = new JobDataMap();
        	dataMap.put(ScheduleJob.JOB_PARAM_KEY, scheduleJob);

            scheduler.triggerJob(getJobKey(scheduleJob.getJobId()), dataMap);
            return true;
        } catch (SchedulerException e) {
            log.info("立即执行定时任务失败{}",e);
            return false;
        }
    }

    */
/**
     * 暂停任务
     *//*

    public static boolean pauseJob(Scheduler scheduler, Long jobId) {
        try {
            scheduler.pauseJob(getJobKey(jobId));
            return true;
        } catch (SchedulerException e) {
            log.info("暂停定时任务失败{}",e);
            return true;
        }
    }

    */
/**
     * 恢复任务
     *//*

    public static boolean resumeJob(Scheduler scheduler, Long jobId) {
        try {
            scheduler.resumeJob(getJobKey(jobId));
            return true;
        } catch (SchedulerException e) {
            log.info("恢复任务失败{}",e);
            return false;
        }
    }

    */
/**
     * 删除定时任务
     *//*

    public static boolean deleteScheduleJob(Scheduler scheduler, Long jobId) {
        try {
            scheduler.deleteJob(getJobKey(jobId));
            return true;
        } catch (SchedulerException e) {
            log.info("删除定时任务失败{}",e);
            return false;
        }
    }
}
*/
